<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>localforage</title>
  <link rel="stylesheet" href="./demo.css">
</head>

<body>
  <div id="app">
    <div class="btn" @click="saveLocalforage">存储</div>
    <div class="btn" @click="getLocalforage">获取</div>
    <div class="btn" @click="deleteLocalforage">删除</div>
  </div>
  <script src="https://cdn.bootcss.com/localforage/1.7.1/localforage.min.js"></script>
  <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.min.js"></script>
  <script>
    new Vue({
      el: '#app',
      created() {
        this.initLocalforage()
      },
      methods: {
        initLocalforage() {
          localforage.config({
            driver: [localforage.WEBSQL,
              localforage.INDEXEDDB,
              localforage.LOCALSTORAGE
            ],
            name: 'WebSQL-Rox'
          })
        },
        saveLocalforage() {
          localforage.setItem('somekey', 'some value').then((value) => {
            console.log(value)
          }).catch(function (err) {
            console.log(err)
          })
        },
        getLocalforage() {
          localforage.getItem('somekey').then((value) => {
            console.log(value)
          }).catch(function (err) {
            console.log(err)
          })
        },
        deleteLocalforage() {
          localforage.removeItem('somekey').then((value) => {
            console.log(value)
          }).catch(function (err) {
            console.log(err)
          })
        }
      }
    })
  </script>
</body>

</html>